// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: leon

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::kraken::feed_v1 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class KrakenFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit KrakenFeedProcessor(const std::string& system_name,
                               const coin2::exchange::di::ConstantInjection& ci,
                               const feed::RawParserConfig& config)
    : FeedParsingProcessor(
          system_name,
          MarketExchangeApi{MarketType::Spot, ExchangeType::Kraken, "v1"},
          ci, config,
          "cc/coin2/exchange/kraken/feed_v1/schema.json") {
  }

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
};

struct KrakenChannel {
  std::string type;

  static KrakenChannel Parse(const std::string& ch) {
    /*
    "book-25"
    "trade"
    */
    std::vector<std::string> splitted;
    splitted = Split(ch, "-");
    CHECK_GE_THROW(splitted.size(), 1) << "unknown channel: " << ch;
    return KrakenChannel{splitted[0]};
  }
};
}  // namespace impl
using impl::KrakenFeedProcessor;
using impl::KrakenChannel;
}  // namespace coin2::exchange::kraken::feed_v1
